package org.jsola.hr.helper;

import org.jsola.common.SafeKit;
import org.jsola.hr.dto.CrmCustomerImportDetailsAddDTO;
import org.jsola.hr.dto.CrmCustomerImportDetailsUpdateDTO;
import org.jsola.hr.entity.CrmCustomerImportDetailsDO;
import org.jsola.hr.query.CrmCustomerImportDetailsQuery;
import org.jsola.hr.service.ICrmCustomerImportDetailsService;
import org.jsola.hr.vo.CrmCustomerImportDetailsVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * 导入客户记录详情表
 *
 * @author zhr
 */
@Component
public class CrmCustomerImportDetailsTestHelper extends BaseTestHelper {
    
    @Autowired
    private ICrmCustomerImportDetailsService crmCustomerImportDetailsService;

    /**
     * 生成add测试数据
     * @return CrmCustomerImportDetailsAddDTO
     */
    public CrmCustomerImportDetailsAddDTO getCrmCustomerImportDetailsAddDTO(){
        CrmCustomerImportDetailsAddDTO crmCustomerImportDetailsAddDTO = new CrmCustomerImportDetailsAddDTO();
        crmCustomerImportDetailsAddDTO.setPostName(getRandomValue("varchar",50));
        crmCustomerImportDetailsAddDTO.setRecordId(getRandomValue("varchar",32));
        crmCustomerImportDetailsAddDTO.setName(getRandomValue("varchar",100));
        crmCustomerImportDetailsAddDTO.setPhone(getRandomValue("varchar",100));
        crmCustomerImportDetailsAddDTO.setGender(SafeKit.getInteger(getRandomValue("int",1)));
        crmCustomerImportDetailsAddDTO.setEmail(getRandomValue("varchar",32));
        crmCustomerImportDetailsAddDTO.setWechat(getRandomValue("varchar",32));
        crmCustomerImportDetailsAddDTO.setFax(getRandomValue("varchar",32));
        crmCustomerImportDetailsAddDTO.setCompanyName(getRandomValue("varchar",100));
        crmCustomerImportDetailsAddDTO.setCompanyAddress(getRandomValue("varchar",100));
        crmCustomerImportDetailsAddDTO.setCompanyType(SafeKit.getInteger(getRandomValue("int",1)));
        crmCustomerImportDetailsAddDTO.setCompanyPersonSize(SafeKit.getInteger(getRandomValue("int",1)));
        crmCustomerImportDetailsAddDTO.setIsError(SafeKit.getBoolean(getRandomValue("tinyint",1)));
        crmCustomerImportDetailsAddDTO.setErrorReason(getRandomValue("varchar",100));
        crmCustomerImportDetailsAddDTO.setIsImport(SafeKit.getBoolean(getRandomValue("tinyint",1)));
        return crmCustomerImportDetailsAddDTO;
    }


    /**
     * 生成update测试数据
     * @return CrmCustomerImportDetailsUpdateDTO
     */
    public CrmCustomerImportDetailsUpdateDTO getCrmCustomerImportDetailsUpdateDTO(CrmCustomerImportDetailsVO crmCustomerImportDetailsVO){
        return crmCustomerImportDetailsService.selectDOById(crmCustomerImportDetailsVO.getId(), SITE_ID).to(CrmCustomerImportDetailsUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return CrmCustomerImportDetailsQuery
     */
    public CrmCustomerImportDetailsQuery getCrmCustomerImportDetailsQuery() {
        CrmCustomerImportDetailsQuery crmCustomerImportDetailsQuery = new CrmCustomerImportDetailsQuery();
        List<CrmCustomerImportDetailsDO> crmCustomerImportDetailsDOList = crmCustomerImportDetailsService.list(new CrmCustomerImportDetailsDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(crmCustomerImportDetailsDOList)) {
            CrmCustomerImportDetailsDO crmCustomerImportDetailsDO = crmCustomerImportDetailsDOList.get(0);
            crmCustomerImportDetailsQuery = crmCustomerImportDetailsDO.to(CrmCustomerImportDetailsQuery.class);
        }
        return crmCustomerImportDetailsQuery;
    }

    /**
     * 保存示例
     * @return CrmCustomerImportDetailsVO
     */
    public CrmCustomerImportDetailsVO saveCrmCustomerImportDetailsExample(){
        CrmCustomerImportDetailsAddDTO addDTO = this.getCrmCustomerImportDetailsAddDTO();
        CrmCustomerImportDetailsVO crmCustomerImportDetailsVO = crmCustomerImportDetailsService.save(addDTO,buildTokenUser());
        return crmCustomerImportDetailsVO;
    }


}

